import {
	PurchasableItemSlug,
	PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
	PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY,
	PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
	PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	PRODUCT_JETPACK_BACKUP_T1_MONTHLY,
	PRODUCT_JETPACK_BACKUP_T1_YEARLY,
	PRODUCT_JETPACK_BACKUP_T2_MONTHLY,
	PRODUCT_JETPACK_BACKUP_T2_YEARLY,
	PLAN_JETPACK_SECURITY_T1_MONTHLY,
	PLAN_JETPACK_SECURITY_T1_YEARLY,
	PLAN_JETPACK_SECURITY_T2_MONTHLY,
	PLAN_JETPACK_SECURITY_T2_YEARLY,
} from '@automattic/calypso-products';
import { useCallback } from 'react';
import useGetProductCardData from './use-get-product-card-data';
import type { SelectorProduct } from 'calypso/my-sites/plans/jetpack-plans/types';

type UpgradesType = {
	[ K in PurchasableItemSlug ]: PurchasableItemSlug[];
};

const UPGRADES: Partial< UpgradesType > = {
	[ PRODUCT_JETPACK_BACKUP_T1_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_T1_YEARLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_T2_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_T2_YEARLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
	[ PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
	[ PLAN_JETPACK_SECURITY_T1_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	],
	[ PLAN_JETPACK_SECURITY_T1_YEARLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_10GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_100GB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
	],
	[ PLAN_JETPACK_SECURITY_T2_MONTHLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
	[ PLAN_JETPACK_SECURITY_T2_YEARLY ]: [
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_1TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_3TB_MONTHLY,
		PRODUCT_JETPACK_BACKUP_ADDON_STORAGE_5TB_MONTHLY,
	],
};

const useGetStorageUpgradeProducts = () => {
	const getProductCardData = useGetProductCardData();

	return useCallback(
		( slug: string ): SelectorProduct[] => {
			const upgrades = UPGRADES[ slug as keyof UpgradesType ] ?? [];

			return upgrades.map( ( slug ) => getProductCardData( slug, false ) as SelectorProduct );
		},
		[ getProductCardData ]
	);
};

export default useGetStorageUpgradeProducts;
